﻿//
// © Algobox Ltd - Benn Eichhorn
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algobox.Objects.Finance.Assets
{
    public class TickStatic : ITick
    {
       #region Constructors

        public TickStatic(string name, decimal tickSize)
        {
            Name = name;
            TickSize = tickSize;
        }

        #endregion

        //////////

        #region Member Variables

        public static TickStatic Default()
        {
            return new TickStatic("DEFAULT", 0.01m);
        }

        #endregion

        //////////

        #region Properties


        public string Name { get; private set; }
        public decimal TickSize { get; private set; }


        #endregion

        //////////

        #region Functions

        public decimal Round(decimal price)
        {
            int tickPriceDivisor = (int)(price / TickSize);
            decimal tickModulor = price % TickSize;

            if (tickModulor / TickSize >= 0.5m)
                return (tickPriceDivisor * TickSize) + TickSize;
            else
                return tickPriceDivisor * TickSize;
        }

        public decimal Round(double price)
        {
            return Round((decimal)price);
        }
        

        public decimal GetTickSize(decimal price)
        {
            return TickSize;
        }

        public decimal GetTickSize(double price)
        {
            return TickSize;
        }

        #endregion

    }
    
}
